import unittest
from examination_util import get_given_answer
from examination_util import list_comparator
from examination_util import examination_score
from examination_util import correct_answer
from examination_util import is_in_time
import datetime
  
class ExaminationTest(unittest.TestCase):
    def test_givenAnswer(self):
        m = {"gruppe0_0":True}
        assert 0 == get_given_answer(0, m)

    def test_givenAnswer2(self):
        m = {"gruppe2_1":True}
        assert 1 ==get_given_answer(2, m)

    def test_givenAnswer3(self):
        m = {"gruppe2_1":True, "gruppe2_0":False}
        assert 1 ==get_given_answer(2, m)

    def test_givenAnswer4(self):
        m = {"gruppe2_1":True, "gruppe2_0":False}
        assert -1 == get_given_answer(0, m)

    def test_givenAnswer5(self):
        m = {"gruppe2_1":True, "gruppe2_0":True}
        assert -2 == get_given_answer(2, m)

    def test_givenAnswer6(self):
        m = {}
        assert -1 == get_given_answer(2, m)

    def test_comparison(self):
        l1 = ["aap", "noot", "Mies"]
        l2 = ["a2ap", "noot", "Mies"]
        assert list_comparator(l1, l2) == 2

    def test_comparison1(self):
        l1 = ["aap", "noot", "Mies"]
        l2 = ["aap", "noot", ""    ]
        assert list_comparator(l1, l2) == 2

    def test_comparison2(self):
        l1 = ["aap", "noot", "Mies"]
        l2 = ["aap", "noot", "Mies"]
        assert list_comparator(l1, l2) == 3
        
    def test_comparison2(self):
        l1 = ["aap", "noot", "Mies"]
        l2 = [""   , "noot", "Mies"]
        assert list_comparator(l1, l2) == 2

    def test_examination_score(self):
        lcorr =  ["0","1"]
        lgiven=  ["0","1"]
        assert examination_score(lcorr, lgiven) == 10

    def test_examination_score2(self):
        lcorr =  ["0","1"]
        lgiven=  ["0","2"]
        assert examination_score(lcorr, lgiven) == 5

    def test_examination_score3(self):
        lcorr =  ["0","1"]
        lgiven=  ["",""]
        assert examination_score(lcorr, lgiven) == 0

    def test_examination_score_exception(self):
        lcorr =  []
        lgiven=  ["1"]
        try:
            examination_score(lcorr, lgiven)
            assert False
        except ValueError:
            pass

    def test_examination_score_exception2(self):
        lcorr =  ["23"]
        lgiven=  ["1", "2"]
        try:
            examination_score(lcorr, lgiven)
            assert False
        except ValueError:
            pass
        
    def test_question_correct_answer(self):
        # create ane empty class without construction
        class C(object): 
            pass
        q = C()
        q.alternatives = ["aap", "noot", "Mies"]
        q.correct = 0
        assert correct_answer(q) == "aap"

    def test_is_in_time1(self):
        d1 = datetime.datetime(1970, 1, 1)
        d2 = datetime.datetime(1970, 1, 1, 1)
        duration = 61
        assert is_in_time(d1, d2, duration)

    def test_is_in_time2(self):
        d1 = datetime.datetime(1970, 1, 1)
        d2 = datetime.datetime(1970, 1, 1, 1)
        duration = 59
        assert not(is_in_time(d1, d2, duration))

if __name__ == "__main__":
    unittest.main()
    
